package com.example.keli.ui.my.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.keli.R;
import com.example.keli.base.adapter.RecyclerAdapter;
import com.example.keli.base.adapter.RecyclerViewHolder;
import com.example.keli.base.utils.LogUtils;
import com.example.keli.ui.my.model.CommissionVO;
import com.example.keli.ui.my.model.GiftVO;

import java.util.List;

/**
 * description $desc$
 * created by jerry on 2019/3/18.
 */
public class GiftAdapter extends BaseQuickAdapter<GiftVO, BaseViewHolder> {

    private int mPositionChecked = 0;
    public GiftAdapter(List<GiftVO> mData, Context context) {
        super(R.layout.item_gift, mData);
    }

    public void setChecked(int position) {
        this.mPositionChecked = position;
    }

    public int getPositionChecked() {
        return mPositionChecked;
    }

    @Override
    protected void convert(BaseViewHolder helper, GiftVO giftVO) {
        ImageView imageView = helper.getView(R.id.iv_gift);
        TextView name = helper.getView(R.id.tv_giftName);
        TextView money = helper.getView(R.id.tv_giftMoney);
        RelativeLayout background = helper.getView(R.id.rootView);
        if (mPositionChecked == helper.getAdapterPosition()) {
            background.setBackgroundResource(R.drawable.border_stoke_bg);
        } else {
            background.setBackgroundResource(0);
        }

        name.setText(giftVO.getGift_name());
        double sum = Double.valueOf(giftVO.getPrice());
        String num = (sum < 1 ? String.valueOf(sum) : String.valueOf((int)sum));
        money.setText(num+"K豆");
        Glide.with(mContext).load(giftVO.getImg()).into(imageView);
    }


}
